//
//  JQFYTicketInfoWebViewController.m
//  JQFY
//
//  Created by apple on 2017/10/19.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYTicketInfoWebViewController.h"
#import "JQFYBuyTicketInfoViewController.h"
#import "JQFYLonginViewController.h"

@interface JQFYTicketInfoWebViewController ()
@property (nonatomic ,strong) UIButton *buyBtn;
@end
@implementation JQFYTicketInfoWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self setupWebView];
}
//初始化UI
-(void)setupUI{
    UIImage *bgImg = [UIImage imageNamed:@"ticket_info_bg"];
    self.view.layer.contents = (id)bgImg.CGImage;
    
    UIImage *leftImg = [UIImage imageNamed:@"ticketInfo_back"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftImg style:UIBarButtonItemStylePlain target:self action:@selector(didClickBack)];
    
    UIView *titView = [[UIView alloc] initWithFrame:CGRectMake(35, 0, 250, 40)];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:titView.bounds];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont fontWithName:@"Verdana-Bold" size:15];
    titleLabel.text = self.model.tickets_title?self.model.tickets_title:@"2017 UNINHIBITED NIGTH";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [titView addSubview:titleLabel];
    self.navigationItem.titleView = titView;
    
    //点击购买按钮
    _buyBtn = [[UIButton alloc] init];
    [self.view addSubview: _buyBtn];
    [_buyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view.mas_bottom).mas_offset(-60);
    }];
    [_buyBtn setBackgroundColor:RGBCOLOR(120, 25, 234)];
    [_buyBtn setTitle:@"点 击 购 买"forState:UIControlStateNormal];
    [_buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_buyBtn.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:18]];
    [_buyBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [_buyBtn addTarget:self action:@selector(didClickBtn) forControlEvents:UIControlEventTouchUpInside
     ];
    
}
//添加webView
-(void) setupWebView{
    WKWebView *webView = [[WKWebView alloc] init];
    [self.view addSubview:webView];
    webView.backgroundColor = [UIColor whiteColor];
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.view);
        make.bottom.mas_equalTo(_buyBtn.mas_top);
    }];
    NSString *str = self.model.tickets_introduce?self.model.tickets_introduce:@"";
    [webView loadHTMLString:str baseURL:[NSURL URLWithString:@"http://app.uninhibited.cn/"]];
}
#pragma mark -
#pragma mark 点击功能
//点击跳转支付页面
-(void)didClickBtn{
    //取出token
    JQFYUserData *data = [JQFYUserData userDataInSandbox];
    if (!data.token) {
        JQFYLonginViewController *Vc = [[JQFYLonginViewController alloc] init];
        [self presentViewController:Vc animated:YES completion:nil];
    }else{
        JQFYBuyTicketInfoViewController *buyVc = [[JQFYBuyTicketInfoViewController alloc] init];
        buyVc.listModel = self.model;
        [self.navigationController pushViewController:buyVc animated:YES];
    }
}
-(void)didClickBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
